package com.firefly.dao.assembler.cms;

import com.firefly.dao.dao.cms.po.CategoryPo;
import com.firefly.dao.dto.cms.CategoryDto;
import com.firefly.dao.vo.cms.CategorySelectVo;
import com.firefly.dao.vo.cms.CategoryTreeVo;
import com.firefly.dao.vo.cms.CategoryVo;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 栏目
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2022/12/20
 **/
@Component
public class CategoryAssembler {
    public List<CategoryTreeVo> getTreeList(List<CategoryVo> list) {
        List<CategoryTreeVo> result = new ArrayList<>();
        list.forEach(item -> {
            CategoryTreeVo tmp = new CategoryTreeVo();
            tmp.setId(item.getId());
            tmp.setParentId(item.getParentId());
            tmp.setName(item.getName());
            tmp.setLinkFlag(item.getLinkFlag());
            tmp.setType(item.getType());
            tmp.setSort(item.getSort());
            result.add(tmp);
        });
        return result;
    }

    public List<CategorySelectVo> getSelectListVo(List<CategoryVo> list) {
        List<CategorySelectVo> result = new ArrayList<>();
        list.forEach(item -> {
            CategorySelectVo tmp = new CategorySelectVo();
            tmp.setId(item.getId());
            tmp.setParentId(item.getParentId());
            tmp.setName(item.getName());
            result.add(tmp);
        });
        return result;
    }

    public CategoryPo getPo(CategoryDto detail){
        CategoryPo entity = new CategoryPo();
        entity.setId(detail.getId());
        entity.setName(detail.getName());
        entity.setThumb(detail.getThumb());
        entity.setTitle(detail.getTitle());
        entity.setKeyword(detail.getKeyword());
        entity.setDescription(detail.getDescription());
        entity.setContent(detail.getContent());
        entity.setLinkFlag(detail.getLinkFlag());
        entity.setUrl(detail.getUrl());
        entity.setCateTpl(detail.getCateTpl());
        entity.setArtTpl(detail.getArtTpl());
        entity.setDisplay(detail.getDisplay());
        entity.setType(detail.getType());
        entity.setSort(detail.getSort());
        return entity;
    }

}
